package com.kehutong.applet.admin;

import com.kehutong.applet.entity.BusinessCallEntity;
import com.kehutong.applet.service.BusinessCallService;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

/**
 * @program: kht
 * @description: 商务管理控制类
 * @author: joneron
 * @create: 2021/5/26
 **/
@MvcAction
@ReqMapping("/admin/crm/applet/business")
public class BusinessController {

    @Inject
    private BusinessCallService businessCallService;

    @ReqMapping("/page")
    @HasPermission("crm:applet:business:view")
    public Object page(JSONObject jsonObject) {
        return businessCallService.findPage(jsonObject);
    }

    @ReqMapping("/list")
    @HasPermission("crm:applet:business:view")
    public Object list(JSONObject jsonObject) {
        return businessCallService.findList(jsonObject);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:applet:business:edit")
    @ReqMapping("/save")
    public Object save(BusinessCallEntity entity, Token token) {
        entity.setCreateName(token.getUsername());
        return businessCallService.save(entity);
    }

    @Bean(copy=true)
    @HasPermission("crm:applet:business:edit")
    @ReqMapping("/update")
    public Object update(BusinessCallEntity entity) {

        return businessCallService.update(entity);
    }

    @HasPermission("crm:applet:business:edit")
    @ReqMapping("/delete")
    public Object delete(BusinessCallEntity entity) {

        return businessCallService.deleteById(entity.getId());
    }

    @ReqMapping("/setStatus")
    @HasPermission("crm:applet:business:edit")
    public Object setStatus(BusinessCallEntity entity) {
        entity.setStatus(!entity.isStatus());
        businessCallService.update(entity);
        return Result.success();
    }

    @ReqMapping("/get")
    public Object get(BusinessCallEntity entity) {

        return Result.success(entity);
    }

}
